import { do_over, do_ready } from './ready';
import { put_log } from 'base/ctl/log';
import { do_inbox } from './inbox';
import { do_box, do_boxscan, do_box_data, do_boxpsn } from './box';
import { do_code, do_tagqr } from './code';
import { do_ckcode } from './ckcode';
import { do_ckpsn, do_hand } from './ckpsn';
import { do_restore, do_box_good, do_select, do_box_style, do_select_tp} from './select';
import { do_scanout, do_ngout, do_outpsn } from './outer';
import { do_oldpick } from './old';
import { do_scanin, do_ngin } from './inner';
import { do_pack } from './pack';
import { do_badin, do_away, do_pout } from './away';
import { do_out, do_inqr, do_outqr } from './inqr';
import { do_repair } from './repair';
import { g_stepnum, g_state } from 'db/state';

let old_st = "";

const do_step = (step, umd, watch) => {
    if (!umd || !watch) {
        return;
    }

    const stepnum = g_stepnum();
    const st = g_state();

    if (old_st !== st) {
        old_st = st;
        put_log("state", st, "当前状态");
    }

    if (st === "ready") {
        do_ready(umd, watch);
        return;
    }

    if (!step) {
        return;
    }

    if (st === "box") {
        do_box(stepnum, step, umd, watch);
    } else if (st === "boxscan") {
        do_boxscan(stepnum, step, umd, watch);
    } else if (st === "boxpsn") {
        do_boxpsn(stepnum, step, umd, watch);
    } else if (st === "inbox") {
        do_inbox(stepnum, step, umd, watch);
    } else if (st === "box_data") {
        do_box_data(stepnum, step, umd, watch);
    } else if (st === "hand") {
        do_hand(stepnum, step, umd, watch);
    } else if (st === "select") {
        do_select(stepnum, step, umd, watch);
    } else if (st === "box_good") {
        do_box_good(stepnum, step, umd, watch);
    } else if (st === "select_tp") {
        do_select_tp(stepnum, step, umd, watch);
    } else if (st === "box_style") {
        do_box_style(stepnum, step, umd, watch);
    } else if (st === "ckpsn") {
        do_ckpsn(stepnum, step, umd, watch);
    } else if (st === "code") {
        do_code(stepnum, step, umd, watch);
    } else if (st === "tagqr") {
        do_tagqr(stepnum, step, umd, watch);
    } else if (st === "ckcode") {
        do_ckcode(stepnum, step, umd, watch);
    } else if (st === "oldpick") {
        do_oldpick(stepnum, step, umd, watch);
    } else if (st === "scanout") {
        do_scanout(stepnum, step, umd, watch);
    } else if (st === "outpsn") {
        do_outpsn(stepnum, step, umd, watch);
    } else if (st === "ngout") {
        do_ngout(stepnum, step, umd, watch);
    } else if (st === "scanin") {
        do_scanin(stepnum, step, umd, watch);
    } else if (st === "ngin") {
        do_ngin(stepnum, step, umd, watch);
    } else if (st === "away") {
        do_away(stepnum, step, umd, watch);
    } else if (st === "pout") {
        do_pout(stepnum, step, umd, watch);
    } else if (st === "badin") {
        do_badin(stepnum, step, umd, watch);
    } else if (st === "restore") {
        do_restore(stepnum, step, umd, watch);
    } else if (st === "outqr") {
        do_outqr(stepnum, step, umd, watch);
    } else if (st === "out") {
        do_out(stepnum, step, umd, watch);
    } else if (st === "inqr") {
        do_inqr(stepnum, step, umd, watch);
    } else if (st === "repair") {
        do_repair(stepnum, step, umd, watch);
    } else if (st === "pack") {
        do_pack(stepnum, step, umd, watch);
    } else if (st === "step_over") {
        do_over(stepnum, umd, watch);
    } else {
        watch.startWatch();
    }
};

export {do_step};
